package cn.tx.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/10/12 20:08
 */
@Configuration
public class FanoutConfig {

    /**
     * 创建交换机
     * @return
     */
    @Bean
    public FanoutExchange exchange() {
        FanoutExchange exchange = new FanoutExchange("logs");
        return exchange;
    }

    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue queue1() {
        Queue queue = new Queue("work1");
        return queue;
    }

    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue queue2() {
        Queue queue = new Queue("work2");
        return queue;
    }

    /**
     * 把队列1绑定到 交换机
     * @return
     */
    @Bean
    public Binding binding1() {
        Binding binding = BindingBuilder.bind(queue1())
                .to(exchange());
        return binding;
    }

    /**
     * 把队列2 绑定到交换机
     * @return
     */
    @Bean
    public Binding binding2() {
        Binding binding = BindingBuilder.bind(queue2())
                .to(exchange());
        return binding;
    }
}
